package Week12;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import java.util.Scanner;

public class moyiTwo2015082 {
	public static void main(String[] args)  {
		String FILENAME = "test.txt";
		
		//write using PrintWriter

		PrintWriter pw=null;
		try {
			pw = new PrintWriter(FILENAME);
			for(int i = 0;i<10000000;i++){
			pw.println(new Random().nextInt(1));
		}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}finally{
			pw.close();
		}
		
		System.out.println("write  using PrintWriter done");
		
		//read using Scanner

		Scanner scanner=null;
		try {
			scanner = new Scanner(new File(FILENAME));
			while(scanner.hasNextLine()){
				scanner.nextLine();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}finally{
			scanner.close();
		}
		System.out.println("read using Scanner done");
		
		//read using BufferedReader

		/*

		BufferedReader br = null;

		try {

			 br = new BufferedReader(new FileReader(new File(FILENAME)));

			while(br.readLine()!=null){};

		} catch (FileNotFoundException e) {

			e.printStackTrace();

		} catch (IOException e) {

			e.printStackTrace();

		}finally{

			try {

				br.close();

			} catch (IOException e) {

				e.printStackTrace();

			}

		}

		System.out.println("read using BufferedReader done");*/
		
		
	}

}

